﻿
@{
    ViewBag.Title = "UploadIndex";
    Layout = "~/Views/Shared/_LayoutForEUI.cshtml";
}

<form id="fm" method="post" enctype="multipart/form-data">
    <div>
        <input class="easyui-textbox" label="上级领导:" style="width:220px" labelalign="right" labelwidth="70px" id="Destroy_Index_txtName" />
    </div>
    <div>
        <input id="file1" class="easyui-filebox" name="file1"  style="width:220px"/>
    </div>
    <div>
        <input type="button" id="btnUpload" style="width:110px;height:30px;" class="easyui-linkbutton button-blue" value="上传" />
    </div>

</form>

<script>
    $(function () {
            $("#file1").filebox({
            width: '300px',//宽度
            prompt: '选择附件...',//提示信息
            buttonText: '选择',//按钮文字
            validType: ['fileSize[1024,"kb"]'],
            accept: 'application/pdf',
            onChange: function () {
                $("#btnUpload").hide();//隐藏上传按钮
                //判断选择的文件是不是Excel
                var temp = $("#file1").filebox('getValue');
                if (temp != '') {
                    var arr = temp.split('.');
                    if (arr.length > 1) {
                        var expanded_name = arr[arr.length - 1].toLowerCase();//取得文件扩展名
                        if (expanded_name == "pdf") {
                            $("#btnUpload").show();
                        }
                        else {//选择了其他类型的文件
                            $("#btnUpload").hide();//隐藏上传按钮
                            alert("请选择pdf文件!");
                            $("#file1").filebox('reset');
                            return;
                        }
                    }
                    else {//选择了无扩展名的文件
                        $("#btnUpload").hide();
                        alert("请选择pdf文件!!");
                        $("#file1").filebox('reset');
                        return;
                    }
                }
            },
        });

        $("#btnUpload").click(function () {
            var temp = $("#file1").filebox('getValue');
                if (temp != '') {
                $('#fm').form('submit', {
                    url: '/Operation/UploadPdf?id=' +'@ViewBag.ID' ,
                    success: function (result) {
                        if (result == '1') {
                            $.messager.alert('提示！', '上传成功!', 'info');
                            //alert(result);
                            parent.window.ClosewinUpLoadGrid();
                        }
                        else {
                            $.messager.alert('提示！', '上传失败!', 'info');
                        }
                    }
                });
            }
            else { $.messager.alert('提示！', '请选择上传文件!', 'info'); }
        });
    })
</script>




